//
//  RequireServerInfoView.m
//  SSB
//
//  Created by Lyn on 16/9/24.
//  Copyright © 2016年 TNT. All rights reserved.
//
#define ScreenWidth [UIScreen mainScreen].bounds.size.width
#define ScreenScale (ScreenWidth / 375.f)


#import "RequireServerInfoView.h"
#import "RequireServerModel.h"
#import "UIColor+GDBAddtion.h"
#import "UIView+PFAddtion.h"
@interface RequireServerInfoView ()

@property (nonatomic, weak) UIImageView *serverImageView;

@property (nonatomic, weak) UILabel *serverNameLabel;

@property (nonatomic, weak) UILabel *serverLevel;

@property (nonatomic, weak) UIImageView *phoneCer;

@property (nonatomic, weak) UIImageView *skillCer;

@property (nonatomic, weak) UIImageView *IDCer;

@property (nonatomic, weak) UILabel *priceTitleLabel;

@property (nonatomic, weak) UILabel *priceLabel;

@property (nonatomic, weak) UIButton *messageBtn;

@property (nonatomic, weak) UIButton *phoneCallBtn;


@end

@implementation RequireServerInfoView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {

    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    if (self = [super initWithCoder:aDecoder]) {
   
    }
    return self;
}

- (void)setModel:(RequireServerModel *)model {
    self.backgroundColor = [UIColor pf_colorWithHexString:@"f7f7f7"];
    
    UIView *contentView = [[UIView alloc]initWithFrame:CGRectMake(10.f, 5.f, ScreenWidth - 20.f , 135.f)];
    contentView.backgroundColor = [UIColor whiteColor];
    contentView.layer.cornerRadius = 4.f;
    [self addSubview:contentView];
    
    UIImageView *serverImageView = [[UIImageView alloc]init];
    /*此处应有sdweb设置图片*/
    serverImageView.image = [UIImage imageNamed:@"require_icon_running"];
    serverImageView.frame = CGRectMake(15.f *ScreenScale , 15.f, 91.f, 91.f);
    serverImageView.contentMode = UIViewContentModeScaleToFill;
    serverImageView.layer.cornerRadius = 40.5f;
    [contentView addSubview:serverImageView];
    self.serverImageView = serverImageView;
    
    UILabel *serverNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(serverImageView.right + 15.f *ScreenScale, 28.f, ScreenWidth / 4.f, 14.f)];
    serverNameLabel.text = model.serverName;
    serverNameLabel.font = [UIFont systemFontOfSize:14.f];
    serverNameLabel.textColor = [UIColor pf_colorWithHexString:@"#333333"];
    [serverNameLabel sizeToFit];
    [contentView addSubview:serverNameLabel];
    self.serverNameLabel = serverNameLabel;
    
    UILabel *serverLevel = [[UILabel alloc]initWithFrame:CGRectMake(serverNameLabel.right + 4.f, 32.f, 50.f, 10.f)];
    serverLevel.textColor = [UIColor pf_colorWithHexString:@"23ceff"];
    serverLevel.text = model.serverLevel;
    serverLevel.font = [UIFont systemFontOfSize:10.f];
    [serverLevel sizeToFit];
    [contentView addSubview:serverLevel];
    self.serverLevel = serverLevel;
    
    NSMutableArray *arrOfCer = [NSMutableArray array];
    if (model.isPhoneCer) {
        [arrOfCer addObject:[UIImage imageNamed:@"require_icon_running"]];
    }
    if (model.isSkillCer) {
        [arrOfCer addObject:[UIImage imageNamed:@"require_icon_running"]];
    }
    if (model.isIDCer) {
        [arrOfCer addObject:[UIImage imageNamed:@"require_icon_running"]];
    }

    
    if (arrOfCer.count) {
        for (int i = (int)(arrOfCer.count - 1); i >= 0; i--) {
            UIImageView *phoneCer = [[UIImageView alloc]initWithImage:arrOfCer[i]];
            phoneCer.frame = CGRectMake(contentView.width - 15.f - 34.f *i, 30.f, 12.f, 12.f);
            [contentView addSubview:phoneCer];
        }
    }
    
    UILabel *serverPriceTitleLabel =  [[UILabel alloc]initWithFrame:CGRectMake(serverImageView.right + 15.f, serverNameLabel.bottom + 18.f, 60.f, 10.f)];
    serverPriceTitleLabel.textColor = [UIColor pf_colorWithHexString:@"888888"];
    serverPriceTitleLabel.text = @"线下服务:";
    serverPriceTitleLabel.font = [UIFont systemFontOfSize:12.f];
    [serverPriceTitleLabel sizeToFit];
    [contentView addSubview:serverPriceTitleLabel];
    self.priceTitleLabel = serverPriceTitleLabel;
    
    UILabel *serverPriceLabel =  [[UILabel alloc]initWithFrame:CGRectMake(serverPriceTitleLabel.right + 15.f, serverNameLabel.bottom + 18.f, 60.f, 10.f)];
    serverPriceLabel.textColor = [UIColor pf_colorWithHexString:@"fd4e77"];
    serverPriceLabel.text = model.serverPrice;
    serverPriceLabel.font = [UIFont systemFontOfSize:12.f];
    [serverPriceLabel sizeToFit];
    [contentView addSubview:serverPriceLabel];
    self.priceLabel = serverPriceLabel;

    UIButton *messageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    messageBtn.frame = CGRectMake(serverImageView.right + 15.f, serverPriceLabel.bottom + 20.f, 79.f *ScreenScale, 26.f);
    [messageBtn setTitle:@"消息" forState:UIControlStateNormal];
    [messageBtn setTitleColor:[UIColor pf_colorWithHexString:@"#45c75a"] forState:UIControlStateNormal];
    messageBtn.layer.masksToBounds = YES;
    messageBtn.layer.cornerRadius = 13.f;
    messageBtn.layer.borderColor = [UIColor pf_colorWithHexString:@"#45c75a"].CGColor;
    messageBtn.layer.borderWidth = 1.f;
    [contentView addSubview:messageBtn];
    self.messageBtn = messageBtn;
    
    UIButton *phoneCallBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    phoneCallBtn.frame = CGRectMake(serverImageView.right + 15.f, serverPriceLabel.bottom + 20.f, 79.f *ScreenScale, 26.f);
    phoneCallBtn.right = contentView.width - 20.f;
    [phoneCallBtn setTitle:@"消息" forState:UIControlStateNormal];
    [phoneCallBtn setTitleColor:[UIColor pf_colorWithHexString:@"#45c75a"] forState:UIControlStateNormal];
    phoneCallBtn.layer.masksToBounds = YES;
    phoneCallBtn.layer.cornerRadius = 13.f;
    phoneCallBtn.layer.borderColor = [UIColor pf_colorWithHexString:@"#45c75a"].CGColor;
    phoneCallBtn.layer.borderWidth = 1.f;
    [contentView addSubview:phoneCallBtn];
    self.phoneCallBtn = phoneCallBtn;
    
}


@end
